package com.jeomo.masterdata.provider.web.controller;

import com.jeomo.common.core.annocation.DataDict;
import com.jeomo.common.core.result.CommonResult;
import com.jeomo.masterdata.provider.web.vo.TestVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: qbt
 * @Date: 2020/8/30 22:33
 * @Version 1.0
 */
@RestController
@RequestMapping("/masterData/test")
public class TestController  {

    @GetMapping("test1")
    @DataDict
    public CommonResult<TestVo> test1() {
        TestVo testVo = new TestVo();
        testVo.setType("1");
        List<String> ids = new ArrayList<>();
        ids.add("1");
        ids.add("2");
        ids.add("3");
        testVo.setIds(ids);
        return CommonResult.success(testVo);
    }

    @GetMapping("test2")
    @DataDict
    public CommonResult<List<TestVo>> test2() {
        List<TestVo> vos = new ArrayList<>();
        for(int i = 0; i < 5; i++) {
            TestVo testVo = new TestVo();
            testVo.setType("type1");
            List<String> ids = new ArrayList<>();
            ids.add("1");
            ids.add("2");
            ids.add("3");
            testVo.setIds(ids);
            vos.add(testVo);
        }
        return CommonResult.success(vos);
    }


    @GetMapping("test3")
    public void test3(HttpServletResponse response) throws IOException {
        String name = String.valueOf(System.currentTimeMillis());
        // 取得输出流
        OutputStream os = response.getOutputStream();
        response.reset();
// 设定输出文件头,该方法有两个参数，分别表示应答头的名字和值。
        response.setHeader("Content-disposition", "attachment; filename=" + name + ".xls");
        response.setContentType("application/msexcel");
//        ExcelUtil.createFixationSheet(os, null);
    }

}
